﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Utility;
using DAL;
using dotnetCHARTING;

public partial class Report_MonthReportCompleteRate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Chart1.Title = "月完成率分析";
        this.Chart1.XAxis.Label.Text = "";
        this.Chart1.YAxis.Label.Text = "完成率";
        this.Chart1.TempDirectory = "../Temp";
        this.Chart1.ShadingEffect = true;
        this.Chart1.SeriesCollection.Add(toChart());
        this.Chart1.Use3D = true;
        this.Chart1.Debug = false;
        this.Chart1.Mentor = false;
    }

    /// <summary>
    /// 定制查询数据 
    /// </summary>
    /// <returns>DataSet</returns>
    public DataSet get()
    {
        string _spName = "Report_MonthReportCompleteRateToChart";
        SqlParameter[] parms = new SqlParameter[1];
        parms[0] = new SqlParameter("@MonthDate", Utility.HttpHelp.getParamsInt("MonthDate"));
        return SqlHelper.ExecuteDataset(SqlHelper.getConn(), CommandType.StoredProcedure, _spName, parms);
    }

    //处理数据提供给图表
    dotnetCHARTING.SeriesCollection toChart()
    {
        dotnetCHARTING.SeriesCollection SC = new dotnetCHARTING.SeriesCollection();

        DataSet ds = get();
        DataTable _tabel = ds.Tables[ds.Tables.Count - 1];
        LegendEntry myEntry = new LegendEntry();
        for (int i = 0; i < _tabel.Rows.Count; i++)
        {
            dotnetCHARTING.Series s = new dotnetCHARTING.Series();
            dotnetCHARTING.Element Pre = new dotnetCHARTING.Element();
            Pre.Name = "上月";
            Pre.ShowValue = true;
            Pre.YValue = Convert.ToDouble(_tabel.Rows[i]["PreMonthCompleteCount"].ToString()) * 100;
            dotnetCHARTING.Element The = new dotnetCHARTING.Element();
            The.Name = "本月";
            The.ShowValue = true;
            The.YValue = Convert.ToDouble(_tabel.Rows[i]["TheMonthCompleteCount"].ToString()) * 100;
            s.Name = _tabel.Rows[i]["DepartmentParentName"].ToString();
            s.Elements.Add(Pre);
            s.Elements.Add(The);
            SC.Add(s); 
        } 

        if (SC.Count == 1)
        {
            SC[0].DefaultElement.Color = System.Drawing.Color.FromArgb(49, 255, 49);
        }
        else
        {
            SC[0].DefaultElement.Color = System.Drawing.Color.FromArgb(49, 255, 49);
            SC[1].DefaultElement.Color = System.Drawing.Color.FromArgb(255, 255, 0);
        }

        return SC;
    }
}
